<!doctype html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Python,log," />





  <link rel="alternate" href="/atom.xml" title="Kingname" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="文章首发地址：http://kingname.info
这篇文章不会教你在技术角度上使用log，而是告诉你为什么要使用log日志功能。
为什么要使用Log在使用微信控制你的电脑这篇文章中，我写好了电脑端的程序，使用py2exe生成可执行文件，并把它们发送给我的朋友让他们进行测试。但是他们把_config.ini设置好以后，运行程序就看到一个黑色窗口一闪而过。或者有些人一开始看到程序能正常登陆邮箱，">
<meta property="og:type" content="article">
<meta property="og:title" content="如何正确使用日志Log">
<meta property="og:url" content="https://kingname.info/2015/01/08/如何正确使用日志log/index.html">
<meta property="og:site_name" content="Kingname">
<meta property="og:description" content="文章首发地址：http://kingname.info
这篇文章不会教你在技术角度上使用log，而是告诉你为什么要使用log日志功能。
为什么要使用Log在使用微信控制你的电脑这篇文章中，我写好了电脑端的程序，使用py2exe生成可执行文件，并把它们发送给我的朋友让他们进行测试。但是他们把_config.ini设置好以后，运行程序就看到一个黑色窗口一闪而过。或者有些人一开始看到程序能正常登陆邮箱，">
<meta property="og:updated_time" content="2016-11-30T13:56:48.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="如何正确使用日志Log">
<meta name="twitter:description" content="文章首发地址：http://kingname.info
这篇文章不会教你在技术角度上使用log，而是告诉你为什么要使用log日志功能。
为什么要使用Log在使用微信控制你的电脑这篇文章中，我写好了电脑端的程序，使用py2exe生成可执行文件，并把它们发送给我的朋友让他们进行测试。但是他们把_config.ini设置好以后，运行程序就看到一个黑色窗口一闪而过。或者有些人一开始看到程序能正常登陆邮箱，">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://kingname.info/2015/01/08/如何正确使用日志log/"/>





  <title> 如何正确使用日志Log | Kingname </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">Kingname</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">给时光以生命。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tweet">
          <a href="/tweet" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-twitter"></i> <br />
            
            时间
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="https://kingname.info/2015/01/08/如何正确使用日志log/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="Kingname">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="/images/avatar.png">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="Kingname">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="Kingname" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                如何正确使用日志Log
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2015-01-08T12:54:46+08:00">
                2015-01-08
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Python/" itemprop="url" rel="index">
                    <span itemprop="name">Python</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <a href="/2015/01/08/如何正确使用日志log/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/01/08/如何正确使用日志log/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>文章首发地址：<a href="http://kingname.info">http://kingname.info</a></p>
<p>这篇文章不会教你在技术角度上使用log，而是告诉你为什么要使用log日志功能。</p>
<h2 id="为什么要使用Log"><a href="#为什么要使用Log" class="headerlink" title="为什么要使用Log"></a>为什么要使用Log</h2><p>在<a href="http://kingname.info/2014/12/23/A-Totally-Amazing/">使用微信控制你的电脑</a>这篇文章中，我写好了电脑端的程序，使用py2exe生成可执行文件，并把它们发送给我的朋友让他们进行测试。但是他们把_config.ini设置好以后，运行程序就看到一个黑色窗口一闪而过。或者有些人一开始看到程序能正常登陆邮箱，但是准备执行命令的时候，窗口自动关闭。</p>
<p>由于没有日志记录程序的运行状态，我根据他们的描述很难定位到错误在哪个地方。于是折腾了一个下午。</p>
<p>这个时候，我觉得添加一个日志的功能迫在眉睫。</p>
<h2 id="哪些地方应该用Log"><a href="#哪些地方应该用Log" class="headerlink" title="哪些地方应该用Log"></a>哪些地方应该用Log</h2><p>目前网上能找到的关于如何使用日志的文章，全部都是从技术角度讲怎么使用log：在XX地方应该先imort logging，然后basicconfig设定XX内容。可是我现在的问题是：</p>
<ul>
<li>应该在程序的哪些地方添加日志的输出？</li>
<li>输出什么内容？</li>
<li>如何输出才能以方便我的监控程序的运行情况？</li>
</ul>
<p>于是我只有自己摸索。因此，<strong>以下内容是我自己摸索出来的野路子，可能会有错漏。希望有经验的朋友能给我指正，非常感谢。</strong></p>
<h3 id="这些地方应该用Log"><a href="#这些地方应该用Log" class="headerlink" title="这些地方应该用Log"></a>这些地方应该用Log</h3><p>使用<a href="http://kingname.info/2014/12/23/A-Totally-Amazing/">使用微信控制你的电脑</a>文章中涉及到的例子</p>
<p>程序入口代码如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">if __name__==&apos;__main__&apos;:</div><div class="line">        init()</div><div class="line">        print u&apos;等待接收命令&apos;</div><div class="line">        logging.info(u&apos;初始化完成。&apos;)</div><div class="line">        while 1:</div><div class="line">                time.sleep(int(time_limit)) #每5分钟检查一次邮箱</div><div class="line">                accp_mail()</div></pre></td></tr></table></figure>
<p>以上代码表示程序运行以后，首先执行init()函数，于是如果init()初始化没有什么问题，成功执行完成以后，就应该在日志中输出“初始化完成”，然后进入接收邮件的循环。如果程序窗口运行以后一闪而过，而且生成的日志中没有初始化完成这样的字眼，那就说明问题出在初始化上面。</p>
<p>然而初始化函数里面代码也有很多，又如何知道是初始化程序里面的什么地方出问题了呢？</p>
<p>所以，再初始化函数里面，也应该有一定的日志记录。</p>
<p>再看初始化函数的代码：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div></pre></td><td class="code"><pre><div class="line">def init():</div><div class="line">        global username,password,host,boss_email,time_limit</div><div class="line">      	 </div><div class="line">		try:</div><div class="line">               f = open(&apos;_config.ini&apos;,&apos;r&apos;)</div><div class="line">       	except IOError,e:</div><div class="line">               logging.error(e)</div><div class="line">			exit()</div><div class="line"></div><div class="line">        info = f.readlines()</div><div class="line">		try:</div><div class="line">	        host = re.search(&apos;host:(.*?)\n&apos;,info[0],re.S).group(1)</div><div class="line">	        username = re.search(&apos;username:(.*?com)&apos;,info[1],re.S).group(1)</div><div class="line">	        password = re.search(&apos;password:(.*?)\n&apos;,info[2],re.S).group(1)</div><div class="line">	        boss_email = re.search(&apos;boss_email:(.*?com)&apos;,info[3],re.S).group(1)</div><div class="line">	        time_limit = re.search(&apos;time_limit:(.*?)\n&apos;,info[4],re.S).group(1)</div><div class="line">		except Exception,e:</div><div class="line">               logging.error(e)</div><div class="line"></div><div class="line">        logging.info(u&apos;打开配置文件成功。。。&apos;)</div><div class="line">		</div><div class="line"></div><div class="line">        #将命令生成字典，便于查询</div><div class="line">        command_start = info.index(&apos;&lt;command&gt;\n&apos;)</div><div class="line">        command_end = info.index(&apos;&lt;/command&gt;\n&apos;)</div><div class="line">        for each in info[command_start+1:command_end]:</div><div class="line">                command = each.split(&apos;=&apos;)</div><div class="line">                command_dict[command[0]] = command[1]</div><div class="line">		</div><div class="line">        logging.info(command_dict)</div><div class="line">		</div><div class="line">        open_start = info.index(&apos;&lt;open_file&gt;\n&apos;)</div><div class="line">        open_end = info.index(&apos;&lt;/open_file&gt;\n&apos;)</div><div class="line">        for each in info[open_start+1:open_end]:</div><div class="line">                open_file = each.split(&apos;=&apos;)</div><div class="line">                open_dict[open_file[0]] = open_file[1][:-1]</div><div class="line">		</div><div class="line">        logging.info(open_dict)</div><div class="line">		</div><div class="line">        f.close()</div></pre></td></tr></table></figure></p>
<p>在这段代码中，我使用try except命令捕获异常，如果发生异常，就使用logging.error将错误写入日志中。例如当_config.ini被改名了或者被删除的时候，程序就会报错，而通过日志就能发现这个错误。</p>
<p>经过上面的代码，如果在初始化的过程中出错，就可以很快确定问题出在什么地方。</p>
<p>初始化完成以后，进入邮件接收阶段。<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div></pre></td><td class="code"><pre><div class="line">def accp_mail():</div><div class="line">        logging.info(u&apos;开始检查邮箱&apos;)</div><div class="line">		try:</div><div class="line">	        pp = poplib.POP3_SSL(host)</div><div class="line">	        pp.set_debuglevel(1)</div><div class="line">	        pp.user(username)</div><div class="line">	        pp.pass_(password)</div><div class="line">	        ret = pp.list()</div><div class="line">	        logging.info(u&apos;登录邮箱成功。&apos;)</div><div class="line">		except Exception,e:</div><div class="line">			logging.error(e)</div><div class="line">			exit()</div><div class="line">		</div><div class="line">		logging.info(u&apos;开始抓取邮件。&apos;)</div><div class="line">		try:</div><div class="line">        	down = pp.retr(len(ret[1]))</div><div class="line">			logging.info(u抓取邮件成功。&apos;&apos;)</div><div class="line">		except Exception,e:</div><div class="line">			logging.error(e)</div><div class="line">			exit()</div><div class="line"></div><div class="line">		logging.info(u&apos;开始抓取subject和发件人&apos;)</div><div class="line">        try:</div><div class="line">               subject = re.search(&quot;Subject: (.*?)&apos;,&quot;,str(down[1]).decode(&apos;utf-8&apos;),re.S).group(1)</div><div class="line">               sender = re.search(&quot;&apos;X-Sender: (.*?)&apos;,&quot;,str(down[1]).decode(&apos;utf-8&apos;),re.S).group(1)</div><div class="line">               logging.info(u&apos;抓取subject和发件人成功&apos;)</div><div class="line">       	except Exception,e:</div><div class="line">               logging.error(e)</div><div class="line">               exit()</div><div class="line"></div><div class="line">        if subject != &apos;pass&apos;:</div><div class="line">                if sender == boss_email:</div><div class="line">                        DealCommand(subject)</div><div class="line">        pp.quit()</div></pre></td></tr></table></figure></p>
<p>以上这段代码，对邮箱的登录与邮件的读取均作了监控，一旦有某个环节出了问题，就会体现在日志中。</p>
<p>通过在登录环节的try except返回的错误日志，发现有很多朋友无法登录邮箱，而密码用户名都没有错，从而推断是没有在新浪邮箱的账户控制里面打开客服端接收POP3和SMTP的功能。</p>
<p>再来看DealCommand()函数：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line">def DealCommand(subject):</div><div class="line">        logging.info(u&apos;开始处理命令。&apos;)</div><div class="line">        send_mail(&apos;pass&apos;,&apos;slave&apos;)</div><div class="line">        if subject in command_dict:</div><div class="line">                logging.info(u&apos;执行命令&apos;)</div><div class="line">                try:</div><div class="line">                        command = command_dict[subject]</div><div class="line">                        os.system(command)</div><div class="line">                        send_mail(&apos;Success&apos;,&apos;boss&apos;)</div><div class="line">                        logging.info(u&apos;执行命令成功&apos;)</div><div class="line">                except Exception,e:</div><div class="line">                        logging.error(e)</div><div class="line">                        send_mail(&apos;error&apos;,&apos;boss&apos;,e)</div><div class="line">        elif subject in open_dict:</div><div class="line">                logging.info(u&apos;打开文件&apos;)</div><div class="line">                try:</div><div class="line">                        open_file = open_dict[subject]</div><div class="line">                        win32api.ShellExecute(0, &apos;open&apos;, open_file, &apos;&apos;,&apos;&apos;,1)</div><div class="line">                        send_mail(&apos;Success&apos;,&apos;boss&apos;)</div><div class="line">                        logging.info(u&apos;打开文件成功&apos;)</div><div class="line">                except Exception,e:</div><div class="line">                        logging.error(e)</div><div class="line">                        send_mail(&apos;error&apos;,&apos;boss&apos;,e)</div><div class="line">        else:</div><div class="line">                send_mail(&apos;error&apos;,&apos;boss&apos;,&apos;no such command&apos;)</div></pre></td></tr></table></figure></p>
<p>执行命令的地方可能会出错，于是果断使用try except捕获错误。并使用日志记录。</p>
<p>最后是send_mail()函数：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div></pre></td><td class="code"><pre><div class="line">def send_mail(subject,flag,body=&apos;Success&apos;):</div><div class="line">        </div><div class="line">        msg = MIMEText(body,&apos;plain&apos;,&apos;utf-8&apos;)#中文需参数‘utf-8’，单字节字符不需要</div><div class="line">        msg[&apos;Subject&apos;] = subject</div><div class="line">        msg[&apos;from&apos;] = username</div><div class="line">        logging.info(&apos;开始配置发件箱。&apos;)</div><div class="line">        try:</div><div class="line">                handle = smtplib.SMTP(&apos;smtp.sina.com&apos;, 25)</div><div class="line">                handle.login(username,password)</div><div class="line">                logging.info(&apos;发件箱配置成功&apos;)</div><div class="line">        except Exception,e:</div><div class="line">                logging.error(e)</div><div class="line">                exit()</div><div class="line"></div><div class="line">        logging.info(u&apos;开始发送邮件&apos;+ &apos;to&apos; + flag)</div><div class="line">        if flag == &apos;slave&apos;:</div><div class="line">                try:</div><div class="line">                        handle.sendmail(username,username, msg.as_string())</div><div class="line">                        logging.info(u&apos;发送邮件成功&apos;)</div><div class="line">                except Exception,e:</div><div class="line">                        logging.error(e)</div><div class="line">                        exit()</div><div class="line">        elif flag == &apos;boss&apos;:</div><div class="line">                try:</div><div class="line">                        handle.sendmail(username,boss_email, msg.as_string())</div><div class="line">                        logging.info(u&apos;发送邮件成功&apos;)</div><div class="line">                except Exception,e:</div><div class="line">                        logging.error(e)</div><div class="line">                        exit()</div><div class="line">                </div><div class="line">        handle.close()</div><div class="line">        logging.info(u&apos;发送邮件结束&apos;+flag)</div></pre></td></tr></table></figure></p>
<p>这里对邮件发件的部分需要特别仔细的错误捕获，然后记录进入日志中。</p>
<p>完整的代码见：<a href="https://github.com/kingname/MCC.git" target="_blank" rel="external">https://github.com/kingname/MCC.git</a>中的auto.py</p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>需要使用日志记录的地方大致有一下几处：</p>
<ul>
<li>所有输入输出处，无论是从文件输入还是从网络等其他地方输入</li>
<li>执行命令处</li>
<li>调用函数处</li>
</ul>
<h2 id="PS"><a href="#PS" class="headerlink" title="PS"></a>PS</h2><p>这里我对一般信息的记录使用了info,实际上，一般用作调试的话，是使用debug更多。</p>
<p>需要用户输入的地方，总会有想不到的错误，多小心都不为过。例如，用户可能会把time_limit设定为一个全角数字。而本文中就没有捕获这种问题到日志中。所以如果不放心的话，还可以更进一步的细化日志。</p>

      
    </div>

    <div>
      
        
<div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/wechatplatform.jpg" alt="Kingname wechat" style="width: 200px; max-width: 100%;"/>
    <div>第一时间获取最新文章更新，请订阅我的微信公众号：未闻Code</div>
</div>


      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Python/" rel="tag"># Python</a>
          
            <a href="/tags/log/" rel="tag"># log</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2015/01/02/使用AWS亚马逊云搭建Gmail转发服务三/" rel="next" title="使用AWS亚马逊云搭建Gmail转发服务（三）">
                <i class="fa fa-chevron-left"></i> 使用AWS亚马逊云搭建Gmail转发服务（三）
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/01/08/清空Github上某个文件的历史/" rel="prev" title="清空Github上某个文件的历史">
                清空Github上某个文件的历史 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.png"
               alt="Kingname" />
          <p class="site-author-name" itemprop="name">Kingname</p>
          <p class="site-description motion-element" itemprop="description">爬虫工程师，极客学院讲师，Python, Scrapy, MongoDB, Redis, Pandas, Golang。</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">42</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">13</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">66</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/kingname" target="_blank" title="Github">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  Github
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="mailto:contact@kingname.info" target="_blank" title="Mail">
                  
                    <i class="fa fa-fw fa-globe"></i>
                  
                  Mail
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Friends
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://chuangzaoshi.com/" title="创造狮" target="_blank">创造狮</a>
                </li>
              
            </ul>
          </div>
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么要使用Log"><span class="nav-number">1.</span> <span class="nav-text">为什么要使用Log</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#哪些地方应该用Log"><span class="nav-number">2.</span> <span class="nav-text">哪些地方应该用Log</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#这些地方应该用Log"><span class="nav-number">2.1.</span> <span class="nav-text">这些地方应该用Log</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">3.</span> <span class="nav-text">总结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#PS"><span class="nav-number">4.</span> <span class="nav-text">PS</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Kingname</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  





  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

  


</body>
</html>
